<template>
  <div>
    <div class="comment-input">
      <textarea placeholder="在这里发表您的看法吧~"></textarea>
      <div>评论</div>
    </div>
    <div class="comment-box">
      <div class="comment-header">
        <div class="comment-logo"></div>
        <div class="title">精彩乐评</div>
        <div class="num">（89）</div>
      </div>
      <div class="comment-footer">
        <div v-for="(item, index) in userList" :key="index" class="list">
          <div class="comment-img">
            <img :src="touxiang" alt="" />
          </div>
          <div class="user-box">
            <div class="user">
              <div class="user-title">{{ item.name }}</div>
              <span class="user-time">{{ item.time }}</span>
              <div class="user-desc">{{ item.content }}</div>
            </div>
            <div class="share">
              <span>
                <img :src="fengxiang" alt="" />
                分享
              </span>
              <span @click="zanHandle(index)">
                <img :src="item.zan" alt="" style="width: 14px; height: 14px" />
                {{ item.like }}
              </span>
              <span @click="commentHandle(index)">
                <img :src="item.pinglun" alt="" />
                {{ item.message }}
              </span>
            </div>
            <div class="comment-comment" v-if="item.iscommentFalg">
              <input type="text" />
              <div class="reply" @click="commentHandle1(index)">回复</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div>
      <Pages :page="980" />
    </div>
  </div>
</template>

<script>
import Pages from "./Pages";
import { Dialog } from "vant";
export default {
  data() {
    return {
      userList: [],
      fengxiang: "http://iwenwiki.com/api/blueberrypai/images/fenxiang_03.png", // 分享
    };
  },
  components: {
    Pages,
  },
  mounted() {
    this.http(1);
    this.$bus.$on("pageVal", (data) => {
      this.http(data);
    });
  },
  methods: {
    zanHandle(index) {
      this.userList[index].isZanFalg = !this.userList[index].isZanFalg;
      if (this.userList[index].isZanFalg) {
        this.userList[index].like += 1;
        this.userList[index].zan =
          "http://iwenwiki.com/api/blueberrypai/indexImg/zan-big_03.png";
      } else {
        this.userList[index].like -= 1;
        this.userList[index].zan =
          "http://iwenwiki.com/api/blueberrypai/image/listenSpeak/gray-appl.png";
      }
    },
    commentHandle(index) {
      this.userList[index].iscommentFalg = !this.userList[index].iscommentFalg;
      this.userList[index].message += 1;
      this.userList[index].message -= 1;
    },
    commentHandle1(index) {
      Dialog.confirm({
        message: "确认回复",
      })
        .then(() => {
          this.userList[index].iscommentFalg = false;
          // on confirm
          this.userList[index].message += 1;
        })
        .catch(() => {
          this.userList[index].iscommentFalg = false;
          this.userList[index].message += 1;
          this.userList[index].message -= 1;
          // on cancel
        });
    },
    http(id) {
      this.$api
        .comment({
          conmment_id: id,
        })
        .then((res) => {
          if (res.data.success) {
            this.touxiang =
              "http://iwenwiki.com/api/" +
              String(res.data.commentInfo.writer.head_pic).slice(24);
            this.userList = res.data.commentInfo.comment;
            for (var i = 0; i < this.userList.length; i++) {
              this.userList[i].zan =
                "http://iwenwiki.com/api/blueberrypai/image/listenSpeak/gray-appl.png";
              this.userList[i].pinglun =
                "http://iwenwiki.com/api/blueberrypai/image/listenSpeak/gray-wechat.png";
              this.userList[i].iscommentFalg = false;
              this.userList[i].isZanFalg = false;
            }
          }
        });
    },
  },
};
</script>

<style lang="less" scoped>
.comment-input {
  width: 750px;
  position: relative;
  margin: 0 auto;
  height: 230px;
  textarea {
    box-sizing: border-box;
    width: 100%;
    height: 120px;
    padding: 10px;
  }
  div {
    box-sizing: border-box;
    width: 100px;
    height: 40px;
    line-height: 30px;
    color: #fff;
    font-size: 20px;
    background: orange;
    padding: 5px 10px;
    border-radius: 5px;
    letter-spacing: 13px;
    text-align: right;
    position: absolute;
    top: 140px;
    right: 0;
  }
}
.comment-box {
  text-align: left;
  width: 750px;
  margin: 0 auto;
  .comment-header {
    .comment-logo {
      width: 5px;
      height: 20px;
      background: orange;
      float: left;
    }
    .title {
      height: 20px;
      line-height: 20px;
      padding-left: 5px;
      letter-spacing: 1px;
      font-size: 18px;
      float: left;
    }
    .num {
      height: 20px;
      line-height: 20px;
      font-size: 18px;
      color: #999;
    }
  }
  .comment-footer {
    border-top: 1px solid #f2f2f2;
    border-bottom: 1px solid #f2f2f2;
    margin-top: 10px;
    padding: 20px;
    overflow: hidden;
    .comment-img {
      width: 50px;
      height: 50px;
      float: left;
      border-radius: 50%;
      overflow: hidden;
      margin-right: 10px;
      img {
        width: 50px;
        height: 50px;
      }
    }
    .user-box {
      float: left;
      width: 650px;
      .user-title {
        float: left;
        margin-right: 10px;
        font-weight: 700;
      }
      .user-time {
        font-size: 12px;
        line-height: 21px;
        height: 21px;
        color: #999;
        display: block;
        margin-bottom: 30px;
      }
      .user-desc {
        font-size: 14px;
        color: #333;
        letter-spacing: 2px;
      }
    }
  }
}
.share {
  float: right;
  margin-top: 20px;
  span {
    margin-left: 20px;
    font-size: 14px;
    color: #999;
  }
}
.list {
  display: block;
  border-bottom: 1px solid #f2f2f2;
  margin-bottom: 20px;
  overflow: hidden;
}
.comment-comment {
  border: 1px solid #999;
  margin: 50px 0 20px;
  background: #f2f2f2;
  overflow: hidden;
  height: 110px;
  input {
    box-sizing: border-box;
    width: 550px;
    height: 35px;
    display: inline-block;
    border: 1px solid #999;
    margin-top: 20px;
    float: left;
  }
  .reply {
    width: 80px;
    height: 35px;
    background: orange;
    color: #fff;
    border-radius: 5px;
    letter-spacing: 15px;
    line-height: 35px;
    text-align: right;
    margin-top: 20px;
    margin-left: 18px;
    float: left;
  }
}
</style>